package com.quanyan.runningriding.web.running.Admin;


import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.validation.base.Update;
import com.quanyan.runningriding.entity.vo.run.VideoVo;
import com.quanyan.runningriding.service.RunVideoService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * RunVideoController
 *
 * @author Tu Chun
 * @date 2016/8/23
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class VideoAdminController {
    @Autowired
    private RunVideoService runVideoService;
    private Logger logger = LoggerFactory.getLogger(VideoAdminController.class);


    @RequestMapping(value = "/batchUploadVideo", method = RequestMethod.POST)
    public APIResponse<?> batchUploadVideo(@RequestBody List<VideoVo> VideoVos) {
        APIResponse<?> result = runVideoService.batchUploadVideo(VideoVos);
        return result;
    }

    @RequestMapping(value = "/videoList", method = RequestMethod.POST)
    public APIResponse<PageObj<List<VideoVo>>> videoList(@RequestBody Map<String, Object> paramMap) {
        Integer pageNum = MapUtils.getInteger(paramMap,"pageNum");
        Integer pageSize = MapUtils.getInteger(paramMap,"pageSize");
        String name =MapUtils.getString(paramMap,"name");
        Byte firstType = MapUtils.getByte(paramMap,"firstType");
        String firstTypeName= MapUtils.getString(paramMap, "firstTypeName");
        Byte secondType = MapUtils.getByte(paramMap,"secondType");
        String secondTypeName= MapUtils.getString(paramMap, "secondTypeName");
        PageObj<List<VideoVo>> result = runVideoService.videoList(name, firstType, firstTypeName, secondType, secondTypeName, pageNum, pageSize);
        return APIResponse.returnSuccess(result);
    }

    @RequestMapping(value = "/updateVideo", method = RequestMethod.POST)
    public APIResponse<?> updateVideo(@RequestBody @Validated(Update.class) VideoVo VideoVo) {
        APIResponse<?> result = runVideoService.updateVideo(VideoVo);
        return result;
    }

    @RequestMapping(value = "/deleteVideo", method = RequestMethod.POST)
    public APIResponse<?> deleteVideo(@RequestBody Map<String, Object> paramMap) {
        Integer VideoId = MapUtils.getInteger(paramMap,"videoId");
        APIResponse<?> result = runVideoService.deleteVideo(VideoId);
        return result;
    }




}
